# ocr_identify.py
import ddddocr
import os


class OcrIdentify:
    def __init__(self):
        # 初始化 OCR 实例
        self.ocr = ddddocr.DdddOcr()

    def identify(self, image_path):
        # 验证图片路径
        if not os.path.exists(image_path):
            raise FileNotFoundError(f"图片 {image_path} 不存在")

        # 读取图片
        with open(image_path, "rb") as f:
            image = f.read()

        # 调用 OCR 识别
        res = self.ocr.classification(image)
        return res


if __name__ == "__main__":
    ocr = OcrIdentify()
    result = ocr.identify("test1.png")  # 确保 test1.png 存在
    print("识别结果:", result)
